<?php
/**
 * 管理中心· 系统管理模块的逻辑处理
 * ============================================================================
 * 版权所有 2017-2020 北京优特世纪科技有限公司，并保留所有权利。
 * 网站地址: http://www.unitewww.com;
 * ============================================================================
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * @since: 1.0
 * @version: 1.0
 **/
namespace Hoteladmin\Model;
use Think\Model;
class SetupModel extends Model{
    /**
     +--------------------------------------------------------------------------
     * 管理欢迎页· 获取会员，商品，订单，提现，充值的数据统计
     * @author: XC跃
     * @date ：2018-06-09
     +--------------------------------------------------------------------------
     */
	public function index_count(){
	    //实例化相关表
	    $usiednt = M('user');
	    $ordient = M('order');
	    $cadient = M('cash');
	    //获取系统参数
	    $conf = tpCache("sGam");
	    //dump($conf);
	    //获取数据
	    $time = strtotime(Date("Y-m-d",time()));
	    $res['usAll']  = $usiednt->where('1')->count();
	    $res['usAct']  = $usiednt->where("`us_state`=1")->count();
	    $res['orAdd']  = $ordient->where("`or_pstate`=2 and `or_xtime`>'".$time."'")->count();
	    $res['fahuo']  = $ordient->where("`or_wstate`=1 and `or_pstate`=2 ")->count();
	    $res['usCash'] = $cadient->where("`ic_state` = 3")->count();
			$res['usCashAll'] = $cadient->where("`ic_state` > 0")->count();
	    $res['usCard'] = $usiednt->where("`us_cstate` = 1 ")->count();
			$res['usCardAll'] = $usiednt->where("`us_cstate`>0")->count();
	    return $res;
	}
	/**
	+--------------------------------------------------------------------------
	 * 实现添加（修改）商城公告的功能
	 * @param $act 操作类型
	 * @author : XC跃
	 * @date : 2018-03-14
	+--------------------------------------------------------------------------
	 */
	public function notiAddEdit($id){
		//实例化相关表
		$ident = M('notice');
		//接收传值
		$data['no_title']= trim(I('post.nname'));
		$data['no_cid']  = trim(I('post.ntype'));
		$data['no_body'] = trim(I('post.nbody'));
		$data['no_atime']= time();
		if(''!=$id){
			$re = $ident->where("`no_id`='".$id."'")->save($data);
		}else{
			$re = $ident->add($data);
		}
		$re>0?$res=1:$res=0;
		return $res;
	}
	/**
	 +--------------------------------------------------------------------------
	 * 实现添加（修改）运费模板的功能
	 * @param $type $id 模板ID
	 * @author : ZJ
	 * @date : 2018-09-10
	 +--------------------------------------------------------------------------
	 */
	public function freight_add_edit($id){
	    //实例化相关表
	    $frident = M('freight');
	    //接收传值
	    $right = $_POST['right'];
	    //dump($right);die;
	    $data['fr_first_heavy'] = trim(I('post.firstHeavy'));
	    $data['fr_first_price'] = trim(I('post.firstPrice'));
	    $data['fr_add_heavy'] = trim(I('post.addHeavy'));
	    $data['fr_add_price'] = trim(I('post.addPrice'));
	    $data['fr_region']  = is_array($right) ? json_encode($right,JSON_UNESCAPED_UNICODE) : '默认';
	    if('默认'==$data['fr_region']){
	        $re = $frident->where("`fr_region`='默认'")->find();
	        count($re)>0?$re=0:$re=1;
	    }else{
	        if('edit'==I('post.act')){
	            $re = $frident->where("`fr_id`='".$id."'")->save($data);
	        }else{
	            //添加运费模板
	            $re = $frident->add($data);
	        }
	    }
	    $re>0?$res=1:$res=0;
	    return $res;
	}
    /**
     +--------------------------------------------------------------------------
     * 实现添加（修改）管理员信息的功能
     * @param $type $id 会员ID
     * @author : XC跃
     * @date : 2018-09-28
     +--------------------------------------------------------------------------
     */
    public function admin_add_edit($id){
        //实例化相关表
        $adident = M('admin');
        //接收传值
        $right = $_POST['right'];
        //dump($right);die;    
        $data['ad_name'] = $name = trim(I('post.uname'));
        $data['ad_phone']= trim(I('post.phone'));
        $data['ad_email']= trim(I('post.email'));
        $data['ad_rid']  = is_array($right) ? implode(',', $right) : '';
        if('edit'==I('post.act')){
            if(''!=I('post.pwds')){
                $data['ad_pwd']= MD5(trim(I('post.pwds')));
            }
            $re = $adident->where("`ad_id`='".$id."'")->save($data);
            //记录操作日志
            addLog(session('admin_auth.usname'),'2','2','编辑'.$name.'用户信息');
        }else{
            //1、添加注册信息
            $data['ad_pwd']  = MD5(trim(I('post.pwds')));
            $data['ad_atime']= time();
            $re = $adident->add($data);
            //2、记录操作日志
            addLog(session('admin_auth.usname'),'2','2','添加'.$name.'用户信息');
        }
        $re>0?$res=1:$res=0;
        return $res;
    }
    /**
     +--------------------------------------------------------------------------
     * 管理欢迎页· 获取服务器配置参数
     * @author: XC跃
     * @date ：2017-04-01
     +--------------------------------------------------------------------------
     */
    public function get_sys_info(){
        $sys_info['os']             = PHP_OS;
        $sys_info['zlib']           = function_exists('gzclose') ? 'YES' : 'NO';//zlib
        $sys_info['safe_mode']      = (boolean) ini_get('safe_mode') ? 'YES' : 'NO';//safe_mode = Off
        $sys_info['timezone']       = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
        $sys_info['curl']			= function_exists('curl_init') ? 'YES' : 'NO';
        $sys_info['web_server']     = $_SERVER['SERVER_SOFTWARE'];
        $sys_info['phpv']           = phpversion();
        $sys_info['ip'] 			= GetHostByName($_SERVER['SERVER_NAME']);
        $sys_info['fileupload']     = @ini_get('file_uploads') ? ini_get('upload_max_filesize') :'unknown';
        $sys_info['max_ex_time'] 	= @ini_get("max_execution_time").'s'; //脚本最大执行时间
        $sys_info['set_time_limit'] = function_exists("set_time_limit") ? true : false;
        $sys_info['domain'] 		= $_SERVER['HTTP_HOST'];
        $sys_info['memory_limit']   = ini_get('memory_limit');
        $sys_info['mysql_version']  = 'MYSQL';
        if(function_exists("gd_info")){
            $gd = gd_info();
            $sys_info['gdinfo'] 	= $gd['GD Version'];
        }else {
            $sys_info['gdinfo'] 	= "未知";
        }
        return $sys_info;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
	
	/**
	 +--------------------------------------------------------------------------
	 * 管理欢迎页· 获取每日资金收支情况
	 * @author: XC跃
	 * @date ：2018-01-12
	 +--------------------------------------------------------------------------
	 */
// 	public function selBobiCount(){	    
// 	    //实例化相关表
// 	    $boindent = M('bobi');
// 	    $boList = $boindent->order("`bo_time` asc")->limit(0,30)->select();
//         foreach($boList as $key=>$val){
//             $ubao .= $val['bo_bao'].",";
//             $order.= $val['bo_order'].",";
//             $good .= $val['bo_good'].",";
//             $user .= $val['bo_user'].",";
//             $rech .= $val['bo_rech'].",";
//             $cash .= $val['bo_cash'].",";
//             $tran .= $val['bo_tran'].",";
//             $time .= "'".Date("m-d",$val['bo_time'])."',";
//         }
//         $array = array(
//             array('name'=>"报单金额",'type'=>'line','data'=>xc_substr($ubao)),
//             array('name'=>"消费订单",'type'=>'line','data'=>xc_substr($order)),
//             array('name'=>"商品成本",'type'=>'line','data'=>xc_substr($good)),
//             array('name'=>"奖金支出",'type'=>'line','data'=>xc_substr($user)),
//             array('name'=>"会员充值",'type'=>'line','data'=>xc_substr($rech)),
//             array('name'=>"会员提现",'type'=>'line','data'=>xc_substr($cash)),
//             array('name'=>"资金冲减",'type'=>'line','data'=>xc_substr($tran)),
//         );
//         foreach($array as $val){
//             $title .= "'".$val['name']."',";
//         }
//         $res['title'] = xc_substr($title,'2');
//         $res['btime'] = xc_substr($time,'2');
//         $res['bbody'] = json_encode($array);
// 	    return $res;
// 	}
	
}